package ru.nsu.fit.iconveyor.example.math.node;

import ru.nsu.fit.iconveyor.conveyor.node.NodeConnection;
import ru.nsu.fit.iconveyor.conveyor.node.OutputNode;

import java.util.Map;
import java.util.Properties;

public class StdOutNumberOutputNode extends OutputNode {
    public static final String INPUT_ARG = "input_arg";

    private final NodeConnection<Double> inputArg;

    public StdOutNumberOutputNode(String id) {
        super(id);

        inputArg = new NodeConnection<Double>(Double.class, NodeConnection.Type.INPUT, INPUT_ARG);

        addNodeConnection(inputArg);
    }

    @Override
    public Map<String, Object> execute(Map<String, Object> resource, Properties prop) {
        Map<String, Object> bundles = resource;

        Double arg = (Double)bundles.get(inputArg.getName());
        System.out.println("Result in node " + getId() + ": " + arg);

        return null;
    }

    @Override
    public Map<String, Object> preExecute(Map<String, Object> availableInputResource, Properties prop) {
        if (availableInputResource.size() > 0)
            return availableInputResource;
        return null;
    }
}
